home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / programs / lora210e.zip / STRUCT.ZIP / LASTCALL.C < prev    next >
C/C++ Source or Header  |  1992-04-07  |  2KB  |  79 lines

  1. /*
  2.                           Lora-CBIS Ver. 2.00
  3.  
  4.              Copyright (c) 1989, 1990, 1991 by Marco Maccaferri.
  5.                           All rights reserved.
  6.  
  7.  
  8.                           Source code examples
  9.                        Set/Read lastcaller record
  10.  
  11.  
  12.   You may use this structures at your own risk. The author cannot guarantee
  13.   that this structures are maintained in all future versions of the program.
  14.   You can freely (and you are encouraged on that) distribute this file
  15.   without limitations.
  16.  
  17.   You can contact the autor at one of the following address:
  18.  
  19.   Marco Maccaferri
  20.   BBS: 39-51-6331730 (2:332/402)
  21.   BIX: marco.m
  22.  
  23. */
  24. #include <stdio.h>
  25. #include <io.h>
  26. #include <time.h>
  27. #include <fcntl.h>
  28. #include <string.h>
  29. #include <mem.h>
  30. #include <sys/stat.h>
  31.  
  32. #include "lora.h"
  33.  
  34. void get_last_caller(task)
  35. int task;
  36. {
  37.    int fd;
  38.    struct _lastcall lastcall;
  39.  
  40.    fd = open("LASTCALL.BBS", O_RDONLY|O_BINARY|O_CREAT,S_IREAD|S_IWRITE);
  41.  
  42.    while (read(fd, (char *)&lastcall, sizeof(struct _lastcall)) == sizeof(struct _lastcall))
  43.    {
  44.       if (lastcall.line != task)
  45.          strcpy(lastcall.name, "None");
  46.    }
  47.  
  48.    close (fd);
  49. }
  50.  
  51. void set_last_caller(usr, task, rate)
  52. struct _usr *usr;
  53. int task, rate;
  54. {
  55.    int fd;
  56.    long tempo;
  57.    struct tm *tim;
  58.    struct _lastcall lc;
  59.  
  60.    fd = open("LASTCALL.BBS", O_APPEND|O_WRONLY|O_BINARY|O_CREAT,S_IREAD|S_IWRITE);
  61.  
  62.    memset((char *)&lc, 0, sizeof(struct _lastcall));
  63.  
  64.    lc.line = task;
  65.    strcpy(lc.name, usr->name);
  66.    strcpy(lc.city, usr->city);
  67.    lc.baud = rate;
  68.    lc.times = usr->times;
  69.    strncpy(lc.logon, &usr->ldate[11], 5);
  70.    tempo = time (NULL);
  71.    tim = localtime (&tempo);
  72.    sprintf(lc.logoff,"%2d:%02d",tim->tm_hour,tim->tm_min);
  73.  
  74.    write(fd, (char *)&lc, sizeof(struct _lastcall));
  75.  
  76.    close (fd);
  77. }
  78.  
  79.